package net.zjitc.controller;

import net.zjitc.entity.dto.GoodsDTO;
import net.zjitc.entity.vo.GoodsVO;
import net.zjitc.service.GoodsService;
import net.zjitc.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 毛若颖
 * @date 2024/12/21 9:38
 */
@RestController
@RequestMapping("/admin/goods")
@CrossOrigin
public class goodsController {
    @Autowired
    private GoodsService goodsService;
    @GetMapping("/list/page/{page}/pagesize/{pagesize}")
    public Result getGoodsList(@RequestHeader String token,@PathVariable Integer page,@PathVariable Integer pagesize){
        GoodsVO goodsVO = new GoodsVO(page, pagesize);
        return goodsService.getGoodsList(goodsVO);
    }
    @GetMapping("/id/{id}")
    public Result getGoodsById(@PathVariable Integer id,@RequestHeader String token){
        return goodsService.getGoodsById(id);

    }
    @PostMapping("/add")
    public Result addGoods(@RequestHeader String token,@RequestBody GoodsDTO goods){
        return goodsService.addGoods(goods);
    }
    @PostMapping("/save")
    public Result saveGoods(@RequestHeader String token,@RequestBody GoodsDTO goods){
        return goodsService.saveGoods(goods);
    }
}
